﻿<Window x:Class="MovingRectangle.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Canvas>
        <Rectangle Width="100" Height="60" x:Name="BlueBox">
            <Rectangle.Fill>
                <SolidColorBrush x:Name="MyAnimatedBrush" Color="Blue" />
            </Rectangle.Fill>
            <Rectangle.Triggers>
                <EventTrigger RoutedEvent="Rectangle.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="BlueBox" Storyboard.TargetProperty="(Canvas.Left)"
                                             From="0" To="200" Duration="00:00:5.00" 
                                             AutoReverse="True" RepeatBehavior="Forever"/>
                            <ColorAnimation Storyboard.TargetName="MyAnimatedBrush" Storyboard.TargetProperty="Color"
                                             To="Yellow" Duration="00:00:5.00" 
                                             AutoReverse="True" RepeatBehavior="Forever"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Rectangle.Triggers>
        </Rectangle>
        <Ellipse Canvas.Top="70" Fill="Red" Width="50" Height="50" x:Name="AnimatedEllipse" MouseEnter="AnimatedEllipse_MouseEnter" MouseLeave="AnimatedEllipse_MouseLeave">
            <Ellipse.Triggers>
                <EventTrigger RoutedEvent="Ellipse.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="AnimatedEllipse"
                                             Storyboard.TargetProperty="(Canvas.Left)"
                                             From="-50" To="300" Duration="00:00:0.88"
                                             AutoReverse="True" RepeatBehavior="Forever" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Ellipse.Triggers>
        </Ellipse>
    </Canvas>
</Window>
